define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {

    var Controller = {
        index: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'user/user/index',
                    add_url: 'user/user/add',
                    edit_url: 'user/user/edit',
                    del_url: 'user/user/del',
                    multi_url: 'user/user/multi',
                    table: 'user',
                }
            });

            var table = $("#table");

            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                sortName: 'user.id',
                fixedColumns: true,
                fixedRightNumber: 1,
                columns: [
                    [
                        {checkbox: true},
                        {field: 'id', title: __('Id'), sortable: true},
                        // {field: 'group.name', title: __('Group')},
                        // {field: 'username', title: __('Username'), operate: 'LIKE'},
                        {field: 'nickname', title: __('Nickname'), operate: 'LIKE'},
                        // {field: 'email', title: __('Email'), operate: 'LIKE'},
                        {field: 'mobile', title: __('Mobile'), operate: 'LIKE'},
                        {
                            field: 'avatar',
                            title: __('Avatar'),
                            events: Table.api.events.image,
                            formatter: Table.api.formatter.image,
                            operate: false
                        },
                        {
                            field: 'invite_code', title: '邀请码'
                        },
                        {
                            field: 'parent_id',
                            title: '邀请人',
                            addClass: "selectpage",
                            extend: "data-source='user/user/index' data-field='mobile'",
                            visible: false,
                        },
                        {
                            field: 'parent_text',
                            title: '邀请人',
                            operate: false
                        },
                        {
                            field: 'parent_num',
                            title: '邀请人数',
                            operate: false
                        },
                        {
                            field: 'real_name',
                            title: '真实姓名'
                        },
                        {
                            field: 'card_num',
                            title: '身份证号'
                        },
                        {
                            field: 'club_id',
                            title: '身份',
                            searchList: {1: __('代理'), 0: __('玩家'), 2: '子俱乐部', 3: '俱乐部', 4: '总俱乐部'},
                            formatter: Table.api.formatter.label
                        },
                        {
                            field: 'real_status',
                            title: '实名状态',
                            searchList: {1: __('已实名'), 0: __('未实名'), 2: '申请重改'},
                            formatter: Table.api.formatter.label
                        },
                        {
                            field: 'status',
                            title: __('Status'),
                            formatter: Table.api.formatter.label,
                            searchList: {normal: __('Normal'), hidden: __('Hidden')}
                        },
                        {
                            field: 'is_test',
                            title: '内部测试号',
                            align: 'center',
                            table: table,
                            searchList: {1: __('是'), 0: __('否')},
                            formatter: Table.api.formatter.toggle,
                        },
                        // {field: 'level', title: __('Level'), operate: 'BETWEEN', sortable: true},
                        {
                            field: 'gender',
                            title: __('Gender'),
                            visible: false,
                            searchList: {1: __('Male'), 0: __('Female')}
                        },
                        {
                            field: 'money',
                            title: "银币",
                            operate: 'BETWEEN',
                            sortable: true,
                            formatter: function (value, row, index) {
                                return '<a href="/xZmdkoqcbN.php/user/money/index?user_id=' + row.id + '" class="btn btn-primary btn-xs btn-dialog btn-report" title="银币" data-table-id="table" ><i class=""></i> ' + value + '</a>';
                            }
                        },
                        {
                            field: 'score', title: __('Score'), operate: 'BETWEEN',
                            sortable: true,
                            formatter: function (value, row, index) {
                                return '<a href="/xZmdkoqcbN.php/user/score/index?user_id=' + row.id + '" class="btn btn-warning btn-xs btn-dialog btn-report" title="积分" data-table-id="table" ><i class=""></i> ' + value + '</a>';
                            }
                        },
                        {
                            field: 'gold', title: "金币", operate: 'BETWEEN',
                            sortable: true,
                            formatter: function (value, row, index) {
                                return '<a href="/xZmdkoqcbN.php/user/gold/index?user_id=' + row.id + '" class="btn btn-info btn-xs btn-dialog btn-report" title="金币" data-table-id="table" ><i class=""></i> ' + value + '</a>';
                            }
                        },
                        {
                            field: 'diamond', title: "钻石", operate: 'BETWEEN',
                            sortable: true,
                            formatter: function (value, row, index) {
                                return '<a href="/xZmdkoqcbN.php/user/diamond/index?user_id=' + row.id + '" class="btn btn-danger btn-xs btn-dialog btn-report" title="钻石" data-table-id="table" ><i class=""></i> ' + value + '</a>';
                            }
                        },
                        {field: 'vip.name', title: 'VIP等级'},
                        {
                            field: 'vip_end_time',
                            title: "会员到期时间",
                            formatter: Table.api.formatter.datetime,
                            operate: 'RANGE',
                            addclass: 'datetimerange',
                            sortable: true
                        },
                        {
                            field: 'is_club',
                            title: '俱乐部状态',
                            searchList: {1: __('是'), 0: __('无'), 2: '审核中'},
                            formatter: Table.api.formatter.label
                        },
                        {
                            field: 'club_name',
                            title: '俱乐部名称'
                        },

                        {
                            field: 'successions',
                            title: __('Successions'),
                            visible: false,
                            operate: 'BETWEEN',
                            sortable: true
                        },
                        {
                            field: 'topup',
                            title: '累计充值/元'
                        },
                        {
                            field: 'withdraw_gold',
                            title: '金币提现/元'
                        },
                        {
                            field: 'withdraw_diamond',
                            title: '钻石提现/元'
                        },
                        {
                            field: 'maxsuccessions',
                            title: __('Maxsuccessions'),
                            visible: false,
                            operate: 'BETWEEN',
                            sortable: true
                        },
                        {
                            field: 'logintime',
                            title: __('Logintime'),
                            formatter: Table.api.formatter.datetime,
                            operate: 'RANGE',
                            addclass: 'datetimerange',
                            sortable: true
                        },
                        {field: 'loginip', title: __('Loginip'), formatter: Table.api.formatter.search},
                        {
                            field: 'jointime',
                            title: __('Jointime'),
                            formatter: Table.api.formatter.datetime,
                            operate: 'RANGE',
                            addclass: 'datetimerange',
                            sortable: true
                        },
                        {field: 'joinip', title: __('Joinip'), formatter: Table.api.formatter.search},
                        {
                            field: 'operate',
                            title: __('Operate'),
                            table: table,
                            events: Table.api.events.operate,
                            formatter: Table.api.formatter.operate,
                            buttons: [
                                {
                                    name: 'pass',
                                    text: "实名重改",
                                    classname: 'btn btn-xs btn-info btn-ajax',
                                    confirm: '确认通过该申请?',
                                    url: 'user/user/pass/id/{ids}',
                                    visible: function (row) {
                                        //返回true时按钮显示,返回false隐藏
                                        if (row.real_status === 2) {
                                            return true;
                                        }
                                        return false;
                                    },
                                    refresh: true, //操作完成后是否刷新列表
                                },
                                {
                                    name: 'notpass',
                                    text: "实名拒绝",
                                    classname: 'btn btn-xs btn-danger btn-ajax',
                                    confirm: '确认拒绝该申请?',
                                    url: 'user/user/notpass/id/{ids}',
                                    visible: function (row) {
                                        //返回true时按钮显示,返回false隐藏
                                        if (row.real_status === 2) {
                                            return true;
                                        }
                                        return false;
                                    },
                                    refresh: true, //操作完成后是否刷新列表
                                },
                                {
                                    name: 'tongguo',
                                    text: "通过俱乐部",
                                    classname: 'btn btn-xs btn-info btn-ajax',
                                    confirm: '确认通过该申请?',
                                    url: 'user/user/tongguo/id/{ids}',
                                    visible: function (row) {
                                        //返回true时按钮显示,返回false隐藏
                                        if (row.is_club === 2) {
                                            return true;
                                        }
                                        return false;
                                    },
                                    refresh: true, //操作完成后是否刷新列表
                                },
                                {
                                    name: 'jiesan',
                                    text: "拒绝俱乐部",
                                    classname: 'btn btn-xs btn-danger btn-ajax',
                                    url: 'user/user/jujue/id/{ids}',
                                    visible: function (row) {
                                        //返回true时按钮显示,返回false隐藏
                                        if (row.is_club === 2) {
                                            return true;
                                        }
                                        return false;
                                    },
                                    refresh: true, //操作完成后是否刷新列表
                                },
                                {
                                    name: 'deduct',
                                    text: __('充值'),
                                    title: __('充值'),
                                    classname: 'btn btn-xs btn-success btn-dialog',
                                    icon: '',
                                    url: 'user/user/deduct/id/{ids}',
                                    success: function () {
                                    },
                                    visible: function (row) {
                                        //返回true时按钮显示,返回false隐藏
                                        return true;
                                    }
                                },
                                {
                                    name: 'topup',
                                    text: __('扣款'),
                                    title: __('扣款'),
                                    classname: 'btn btn-xs btn-primary btn-dialog',
                                    icon: '',
                                    url: 'user/user/topup/id/{ids}',
                                    success: function () {
                                    },
                                    visible: function (row) {
                                        //返回true时按钮显示,返回false隐藏
                                        return true;
                                    }
                                },
                                {
                                    name: 'fengjin',
                                    text: "封禁",
                                    classname: 'btn btn-xs btn-danger btn-ajax',
                                    confirm: '确认封禁该用户?',
                                    url: 'user/user/banned/id/{ids}',
                                    visible: function (row) {
                                        //返回true时按钮显示,返回false隐藏
                                        if (row.status === 'normal') {
                                            return true;
                                        }
                                        return false;
                                    },
                                    refresh: true, //操作完成后是否刷新列表
                                },
                                {
                                    name: 'jiejin',
                                    text: "解禁",
                                    classname: 'btn btn-xs btn-info btn-ajax',
                                    confirm: '确认解禁该用户?',
                                    url: 'user/user/normald/id/{ids}',
                                    visible: function (row) {
                                        //返回true时按钮显示,返回false隐藏
                                        if (row.status === 'hidden') {
                                            return true;
                                        }
                                        return false;
                                    },
                                    refresh: true, //操作完成后是否刷新列表
                                },
                            ]
                        }
                    ]
                ]
            });

            // 为表格绑定事件
            Table.api.bindevent(table);
        },
        add: function () {
            Controller.api.bindevent();
        },
        edit: function () {
            Controller.api.bindevent();
        },
        deduct: function () {
            Controller.api.bindevent();
        },
        topup: function () {
            Controller.api.bindevent();
        },
        api: {
            bindevent: function () {
                Form.api.bindevent($("form[role=form]"));
            }
        }
    };
    return Controller;
});